/*
 * 1002:设计一个算法，计算出n阶乘中尾部零的个数
 * https://www.lintcode.com/problem/trailing-zeros/description
 * 
 * 参考：
 * https://blog.csdn.net/surp2011/article/details/51168272
 * 2018.05.31 @jeyming
 */
package trailing_zeros;

//import java.math.BigInteger;

public class Main {

	static long trailingZeros(long n) {
//		 write your code here, try to do it without arithmetic operators.
//		//野蛮方法
//		//BigInteger的使用方法
//		//https://blog.csdn.net/songjunyan/article/details/40743881
//		long cnt=0;
//		BigInteger bigsum=new BigInteger("1");
//		for(long i=1;i<=n;++i) {
//			bigsum=bigsum.multiply(BigInteger.valueOf(i));
//		}
//		//StringBuffer的使用方法
//		// https://www.cnblogs.com/liu-chao-feng/p/5636063.html
//		// http://www.runoob.com/java/java-stringbuffer.html
//		StringBuffer number=new StringBuffer(bigsum.toString());
//		for(int i1=(number.length()-1);(number.charAt(i1)=='0');--i1) {
//			++cnt;
//		}
//		return cnt;
		
		//
		//每5个数产生一个0，然后又在5个数中产生一个0，一直循环下去
		long cnt=0;
		while(n/5!=0){
		    cnt+=n/5;
		    n/=5;
		}
		return cnt;
	}
	 
	public static void main(String[] args) {
		// TODO Auto-generated method stub

//		for(int i=1;i<=100;++i) {
//			System.out.println(trailingZeros(i));
//		}
		long num=trailingZeros(1001171717);
		System.out.println(num);
	}


}
